---
- name: add repo
  copy: src=cabal-install.repo dest=/etc/yum.repos.d/cabal-install.repo
  tags:
  - cabal-install
  - packages
  - repo

- name: install needed packages
  dnf: pkg={{ item }} state=present
  with_items:
  - ghc
  - ghc-devel
  - git
  - cabal-install
  - zeromq3-devel
  tags:
  - packages
  - fedmsg2statsd

- name: Clone fedmsg2statsd repo (this needs to be packaged at some point)
  git: accept_hostkey=yes clone=yes repo=https://github.com/fedora-infra/fedmsg2statsd.git update=yes dest=/opt/fedmsg2statsd
  register: git_result
  changed_when: "git_result.after|default('after') != git_result.before|default('before')"
  tags:
  - fedmsg2statsd

- name: Update cabal metadata
  shell: cabal update
  tags:
  - fedmsg2statsd

- name: Start a cabal sandbox
  shell: chdir=/opt/fedmsg2statsd cabal sandbox init
  tags:
  - fedmsg2statsd

- name: Install fedmsg2statsd in the sandbox
  shell: chdir=/opt/fedmsg2statsd cabal install -j
  tags:
  - fedmsg2statsd

- name: Installing systemd service file
  copy: >
    src=fedmsg2statsd.service
    dest=/usr/lib/systemd/system/fedmsg2statsd.service
  tags:
  - config
  - fedmsg2statsd
  notify:
  - restart fedmsg2statsd

- name: Set fedmsg2statsd to run on boot
  service: name=fedmsg2statsd enabled=yes state=started
  tags:
  - service
  - fedmsg2statsd
